package com.he.projects.custom.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.he.projects.custom.bean.menu.MenuList;
import com.he.projects.custom.bean.ResultT;
import com.he.projects.custom.dao.MenuDao;
import com.he.projects.custom.entity.Menu;
import com.he.projects.custom.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author heyanjing
 * date:2020-07-13 2020/7/13:20:49
 */
@Slf4j
@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;

    @PostMapping("/menu/add1")
    public ResultT add1(@RequestBody Menu menu) {
        log.info("{}", JSONUtil.toJsonStr(menu));
        return ResultT.success();
    }
    @RequestMapping("/menu/add2")
    public ResultT add2(Menu menu) {
        return menuService.insert(menu);
    }

    @GetMapping("/menu/tree/list")
    public ResultT treeList() {
        // String json = "[{\"id\": 1, \"name\": \"zzz\", \"open\": true, \"children\": [{\"id\": 2, \"name\": \"1\", \"open\": false, \"checked\": true}, {\"id\": 3, \"name\": \"2\", \"open\": false, \"checked\": true}, {\"id\": 17, \"name\": \"3z\", \"open\": false, \"checked\": true}], \"checked\": true}, {\"id\": 4, \"name\": \"评论\", \"open\": false, \"children\": [{\"id\": 5, \"name\": \"留言列表\", \"open\": false, \"checked\": false}, {\"id\": 6, \"name\": \"发表留言\", \"open\": false, \"checked\": false}, {\"id\": 333, \"name\": \"233333\", \"open\": false, \"checked\": false}], \"checked\": false}, {\"id\": 10, \"name\": \"权限管理\", \"open\": false, \"children\": [{\"id\": 8, \"name\": \"用户列表\", \"open\": false, \"children\": [{\"id\": 40, \"name\": \"添加用户\", \"open\": false, \"url\": null, \"title\": \"40\", \"checked\": false, \"level\": 2, \"check_Child_State\": 0, \"check_Focus\": false, \"checkedOld\": false, \"dropInner\": false, \"drag\": false, \"parent\": false}, {\"id\": 41, \"name\": \"编辑用户\", \"open\": false, \"checked\": false}, {\"id\": 42, \"name\": \"删除用户\", \"open\": false, \"checked\": false}], \"checked\": false}, {\"id\": 11, \"name\": \"角色列表\", \"open\": false, \"checked\": false}, {\"id\": 13, \"name\": \"所有权限\", \"open\": false, \"children\": [{\"id\": 34, \"name\": \"添加权限\", \"open\": false, \"checked\": false}, {\"id\": 37, \"name\": \"编辑权限\", \"open\": false, \"checked\": false}, {\"id\": 38, \"name\": \"删除权限\", \"open\": false, \"checked\": false}], \"checked\": false}, {\"id\": 15, \"name\": \"操作日志\", \"open\": false, \"checked\": false}], \"checked\": false}]";
        // JSONArray jsonArray = JSONUtil.parseArray(json);
        // return JSONUtil.toList(jsonArray, MenuList.class);
        return this.menuService.treeList();
    }
    @GetMapping("/menu/find")
    public ResultT<List<Menu>> find() {
        return this.menuService.find();
    }

}
